﻿using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using System;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Xml.Schema;

namespace ScormModel
{
    [Serializable()]
    public class RollupRules
    {
        private string _rollupObjectiveSatisfied = null;
        private string _rollupProgressCompletion = null;
        private string _objectiveMeasureWeight = null;
        private List<RollupRule> _listRollupRule;
         [NonSerialized]
        private XmlNode _rollupRulesContent;
        [XmlAttribute("rollupObjectiveSatisfied")]
        public string RollupObjectiveSatisfied
        {
            get { return this._rollupObjectiveSatisfied; }
            set { this._rollupObjectiveSatisfied = value; }
        }
        [XmlAttribute("rollupProgressCompletion")]
        public string RollupProgressCompletion
        {
            get { return this._rollupProgressCompletion; }
            set { this._rollupProgressCompletion = value; }
        }
        [XmlAttribute("objectiveMeasureWeight")]
        public string ObjectiveMeasureWeight
        {
            get { return this._objectiveMeasureWeight; }
            set { this._objectiveMeasureWeight = value; }
        }
        [XmlElement("rollupRule", Namespace = "http://www.imsglobal.org/xsd/imsss")]
        public List<RollupRule> ListRollupRule
        {
            get { return this._listRollupRule; }
            set { this._listRollupRule = value; }
        }
        
        [XmlIgnoreAttribute]
        public XmlNode RollupRulesContent
        {
            get { return this._rollupRulesContent; }
            set { this._rollupRulesContent = value; }
        }
        public void buildRollupRules()
        {
            XmlAttributeCollection attList = _rollupRulesContent.Attributes;
            if (attList.GetNamedItem("rollupObjectiveSatisfied") != null)
            {
                _rollupObjectiveSatisfied = ((XmlAttribute)attList.GetNamedItem("rollupObjectiveSatisfied")).Value;
            }
            if (attList.GetNamedItem("rollupProgressCompletion") != null)
            {
                _rollupProgressCompletion = ((XmlAttribute)attList.GetNamedItem("rollupProgressCompletion")).Value;
            }
            if (attList.GetNamedItem("objectiveMeasureWeight") != null)
            {
                _objectiveMeasureWeight = ((XmlAttribute)attList.GetNamedItem("objectiveMeasureWeight")).Value;
            }
            _listRollupRule = new List<RollupRule>();
            for (int i = 0; i < _rollupRulesContent.ChildNodes.Count; i++)
            {
                if (((XmlNode)(_rollupRulesContent.ChildNodes[i])).Name == "imsss:rollupRule")
                {
                    RollupRule rollupRule = new RollupRule();
                    rollupRule.RollupRuleContent = _rollupRulesContent.ChildNodes[i];
                    rollupRule.buildRollupRule();
                    _listRollupRule.Add(rollupRule);
                }
            }
        }
    }
}
